-- splash_line
-- created by chendh
-- 攻击概率对同排显性怪造成伤害

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 攻击时触发
    trigger = function(who, prop, arg)
        local target = arg;
        if  who.type ~= OBJECT_TYPE_USER or not target then
            return false;
        end

        -- 概率
        local rand = DungeonM.getRandSeed("splash_line") % 1000;
        if rand >= tonumber(prop[2]) then
            -- 概率事件没发生
            return false;
        end

        local damage = math.modf(who:getAttack() * prop[3] / 1000);
        damage = math.max(1, damage);

        -- 选出所有的已显形的怪物
        local grids = DungeonM.getCurrentDungeon();
        for _, grid in pairs(grids) do
            local ok = true;
            -- 格子还没翻开或者不是怪物或者已死亡
            if  not grid:isOpened() or
                not grid:isMonster() or grid.monster:isDead() then
                ok = false;
            end

            if ok and target:getPos() ~= grid:getPos() and
                math.floor((grid:getPos() - 1) / DUNGEON_WIDTH) == math.floor((target:getPos() - 1) / DUNGEON_WIDTH) then
                -- 攻击一下
                --SkillM.hit(who, grid.monster, 0);
                CombatM.receiveDamage(who, grid.monster, damage);
            end
        end

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};
